import datetime
import os
import sys
from settings import EXPIRE_DAY
import oss2
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.append(parent_dir)
from settings import TEST


def upload_file_oss(local_file_name):
    # 填写RAM用户的访问密钥（AccessKey ID和AccessKey Secret）。
    # 客一客云密钥
    accessKeyId = 'LTAI5tPhMzS9qSShvWsso3ZG'
    accessKeySecret = 'ROC9ApAX98TTgDCZIWTPjnTiGJe3nU'
    # 数鲸云密钥
    accessKeyId = 'LTAI5tDsET7v8GtPBr8VEbXV'
    accessKeySecret = '6GECmafA2joN0XKUIZNls8Z0lIghvq'
    # 使用代码嵌入的RAM用户的访问密钥配置访问凭证。
    auth = oss2.Auth(accessKeyId, accessKeySecret)
    # bucket = oss2.Bucket(auth, 'https://oss-cn-shenzhen.aliyuncs.com', 'sj-media')
    bucket = oss2.Bucket(auth, 'https://ai.kykyun.com', 'sj-media', is_cname=True)
    today = datetime.date.today()
    oss_file_name = os.path.basename(local_file_name)

    oss_file_path = '/'.join(['test' if TEST else 'ai', '-'.join([str(today.year), str(today.month)]), oss_file_name])
    bucket.put_object_from_file(oss_file_path, local_file_name)
    expire_time = 3600 * 24 * EXPIRE_DAY
    url = bucket.sign_url('GET', oss_file_path, expire_time, slash_safe=True)
    return url

# path  = r'C:\Users\DELL\Desktop\d3e6a44437f003f2010c6b628b0ceeb8.mp4'
# url = upload_file_oss(path)
# print('url',url)
